#pragma once

#include"HiKernel/HiModule.h"


class HI_DLLEXPORT mHiTerrain : public HiModule
{
private:

	struct sTerrainFile
	{
		std::string sTerrainFName;
		std::string sWorldMapFName;

	};

	std::vector<sTerrainFile*> m_vTerrainName;

	NiNodePtr m_pNode;
	NiPoint3 m_kNormal;

	NiPoint3 kCameraDirection;
	NiPoint3 kCameraPickPos;
	NiPoint3 kCameraPos;
	NiPoint3 kCharacterDirection;

protected:

	D3DXVECTOR3			m_vTrans;
	HiSFVec3f			*m_vVec3f;

	D3DXVECTOR3			m_vTranskNormal;
	HiSFVec3f			*m_vVec3fkNormal;

	D3DXVECTOR3			m_vCameraPickTrans;
	HiSFVec3f			*m_vVec3fCameraPickTrans;


public:


	mHiTerrain(HiXmlNode*xml=NULL);                                   
	virtual ~mHiTerrain() {}          

	void PostConfig();
	void Update();     
	void Render();    

	void			Realize();

	bool HandleMessage(const Telegram& msg);

	int ParseXml(HiXmlNode*xml);// {return 1;};
	int SetXmlAttrs(HiXmlNode*xml)                  { return 1; }

	bool Initialize(const char* pcPickFilename);
	bool GetHeight(float fX, float fY, float &fHeight) ;
	bool GetHeightAndNormal(float fX, float fY, 
		float &fHeight, NiPoint3& kNormal);
	void TransformModelToWorldInPlace(NiAVObject* pkObj, 
		bool bNormals);
	void TransformPointsBasicInPlace(unsigned short uiVerts,
		float* pModel, const NiTransform* pXform);
	void TransformVectorsBasicInPlace(unsigned short uiVerts,
		float* pModel, const NiTransform* pXform);

	bool mHiTerrain::GetCameraPosition(float fX, float fY, float fHeight) ;

	NiAVObjectPtr m_spTerrainGraph;
	NiPick m_kGroundPick;

};